const User=require("./user")
const Blog=require("./blog")
const Group=require("./group")
const Img=require("./img")
const UserFavor=require("./userFavor")
// 用户 博客
// user:blog => 1:n
User.hasMany(Blog, {
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE'
})
Blog.belongsTo(User)

// 博客 图片
//blog:img=>1:n
Blog.hasMany(Img, {
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE'
})
Img.belongsTo(Blog)

// 用户:分组=> 1:n
User.hasMany(Group, {
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE'
})
Group.belongsTo(User)

// 用户关注
//user:user=>m:n
// followId 关注人ID userId被关注人ID
User.belongsToMany(User,{
    as:'user',
    through:UserFavor,
    foreignKey:'userId'
})
User.belongsToMany(User,{
    as:"follow",
    through:UserFavor,
    foreignKey:'followId'
})
// 被关注人的分组
// group:user => m:n
Group.belongsToMany(User,{
    as:"followUser",
    through:"folllowGroup"
})
User.belongsToMany(Group,{
    through:"folllowGroup"
})

module.exports={
    User,
    Blog,
    Group,
    Img,
    UserFavor
}